import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

/**
 * Created by berkbozkurt on 07/03/15.
 */
public class MenuPanel extends JPanel {

    private JButton startGameButton;
    private JButton settingsGameButton;
    private JButton quitGameButton;
    public MenuPanel() {


        setBackground(Color.black);
        // Initial setup
        startGameButton = new JButton("Start Game");
        startGameButton.setSize(new Dimension(500, 100));
        startGameButton.setForeground(Color.black);

        // Center the startGameButton
        startGameButton.setLocation(
                (Application.getInstance().getWidth() / 2) - (this.getWidth() / 2),
                ((Application.getInstance().getHeight() / 2) - (this.getHeight() / 2) ) * 1 / 4);

        settingsGameButton = new JButton("Settings");
        settingsGameButton.setSize(new Dimension(500, 100));
        settingsGameButton.setForeground(Color.black);

        // Center the startGameButton
        settingsGameButton.setLocation(
                (Application.getInstance().getWidth() / 2) - (this.getWidth() / 2),
                ((Application.getInstance().getHeight() / 2) - (this.getHeight() / 2)) * 2 / 4);

        quitGameButton = new JButton("Quit");
        quitGameButton.setSize(new Dimension(500, 100));
        quitGameButton.setForeground(Color.black);

        // Center the startGameButton
        quitGameButton.setLocation(
                (Application.getInstance().getWidth() / 2) - (this.getWidth() / 2),
                ((Application.getInstance().getHeight() / 2) - (this.getHeight() / 2)) * 3 / 4);


        // Set font
        try {
            Font font = Font.createFont(Font.TRUETYPE_FONT, new File("resources/game.ttf"));
            Font biggerFont = font.deriveFont(Font.PLAIN, 48f);
            startGameButton.setFont(biggerFont);
            settingsGameButton.setFont(biggerFont);
            quitGameButton.setFont(biggerFont);

        } catch (IOException | FontFormatException ex) {
            ex.printStackTrace();
        }

        this.add(startGameButton);
        this.add(settingsGameButton);
        this.add(quitGameButton);

        this.validate();
        this.repaint();

        // Player started the game
        startGameButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {

                // Get logicController instance
                GameController logic = GameController.getInstance();
                // Create playing state and update it
                PlayingState playingState = new PlayingState();
                playingState.updateState(logic.getCurrentState());
                logic.configureState();
            }
        });
    }
}
